package app.controllers;

import app.DetailWindow;
import app.MultimediaItem;
import app.models.MultimediaModel;
import framework.FRDModel;
import framework.multimedia.FRDMultimedia;
import framework.multimedia.FRDMultimediaController;
import framework.multimedia.FRDMultimediaItem;
import java.awt.event.ActionEvent;
import java.util.LinkedList;
import javax.swing.JButton;

/**
 *
 * @author Lukáš Marek
 */
public class MultimediaController extends FRDMultimediaController
{
	public MultimediaController(FRDMultimedia panel, FRDModel model)
	{
		super(panel, model);
	}
	
	@Override
	protected void initMultimediaItems()
	{
		items = new MultimediaItem[showingItems];
		for (int i = 0; i < showingItems; i++)
		{
			items[i] = new MultimediaItem();
		}
		multimediaPanel.jItemPanel.add(items[0]);
		multimediaPanel.jItemPanel1.add(items[1]);
		multimediaPanel.jItemPanel2.add(items[2]);
		multimediaPanel.jItemPanel3.add(items[3]);
		multimediaPanel.jItemPanel4.add(items[4]);
		multimediaPanel.jItemPanel5.add(items[5]);
	}

	@Override
	protected LinkedList<String> setParameters()
	{
		LinkedList<String> ret = super.setParameters();
		ret.add(multimediaPanel.imageTextField.getText());
		return ret;
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		JButton button = (JButton) e.getSource();
		switch (button.getActionCommand())
		{
			case "detailButton":
				FRDMultimediaItem item;
				if (e.getSource() instanceof JButton)
				{
					item = (FRDMultimediaItem) ((JButton)e.getSource()).getParent();
					(new DetailWindow((MultimediaModel) model, item.getId())).setVisible(true);
					loadItems();
					multimediaPanel.repaint();
				}
				break;
			case "addButton":
				(new DetailWindow((MultimediaModel) model, -1)).setVisible(true);
				loadItems();
				multimediaPanel.repaint();
				break;
			case "deleteButton":
				FRDMultimediaItem item2;
				if (e.getSource() instanceof JButton)
				{
					item2 = (FRDMultimediaItem) ((JButton)e.getSource()).getParent();
					((MultimediaModel) model).deleteObject(item2.getId());
					loadItems();
					multimediaPanel.repaint();
				}
				break;
			default:
				super.actionPerformed(e);
				break;
		}
	}
}
